<?php

abstract class ParamHandler {

	protected $source;
	protected $params = array();

	function __construct($source) {
		$this->source = $source;
	}

	function addParam($key, $val) {
		$this->params[$key] = $val;
	}

	function getAllParams() {
		return $this->params;
	}

	/**
	 * Depending of the filename extensions, the object returned
	 * can have one of the two subclasses types
	 *
	 * @param unknown_type $filename
	 * @return XmlParamHandler|TextParamHandler
	 */
	static function getInstance($filename) {
		if (preg_match("/\.xml$/i", $sourceFile)) {
			return new XmlParamHandler($filename);
		}
		else {
			return new TextParamHandler($filename);
		}
	}

	// abstract
	abstract function write();
	abstract function read();

}



/**
 * Class to write XML
 * @author adriano
 *
 */
class XmlParamHandler extends ParamHandler {

	function write() {
		// write xml
		// using $this->params
	}

	function read() {
		// read xml
		// and populate $this->params
	}
}



/**
 * Class to write text
 * @author adriano
 *
 */
class TextParamHandler extends ParamHandler {

	function write() {
		// write xml
		// using $this->params
	}

	function read() {
		// read xml
		// and populate $this->params
	}
}


// write xml data
$test = ParamHandler::getInstance("param.xml");
$test->addParam('key1', 'val1');
$test->addParam('key2', 'val2');
$test->addParam('key3', 'val3');
$test->write();

// read as normal text
$test = ParamHandler::getInstance('param.txt');
$test->read();




?>